Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Better suggestions when user tries to collect into an unsized [_] #91443

Merged
merged 2 commits into from
Feb 10, 2022

Conversation

compiler-errors
Copy link
Member

  1. Extend the predicate on rustc_on_unimplemented to support substitutions like note, label, etc (i.e. treat it as a OnUnimplementedFormatString) so we can have slightly more general rustc_on_unimplemented special-cases.
  2. Add a rustc_on_unimplemented if we fail on FromIterator<A> for [A] which happens when we don't explicitly collect into a vec<A>, but then pass the return from a .collect call into something that takes a slice.

Fixes #91423

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 2, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 9, 2021
@Aaron1011
Copy link
Member

Could you add a test case demonstrating the new behavior?

@compiler-errors
Copy link
Member Author

@Aaron1011 added a test. Still unclear what the best wording for this specific suggestion is, but demonstrating that it works.

@bors
Copy link
Contributor

bors commented Jan 27, 2022

☔ The latest upstream changes (presumably #93352) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors
Copy link
Member Author

howdy @matthewjasper, should I reassign this PR to someone else on the high-five queue?

@matthewjasper
Copy link
Contributor

Yes please

@compiler-errors
Copy link
Member Author

reassigning per reviewer request

r? rust-lang/compiler

@wesleywiser
Copy link
Member

@compiler-errors This looks great! My only suggestion was going to be to mention the Sized trait but I see the other errors and notes generated do that already. Could you rebase and fix the merge conflict? Thanks!

@compiler-errors
Copy link
Member Author

Alright @wesleywiser, rebased and confirmed tests still pass!

@wesleywiser
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 9, 2022

📌 Commit fea0015 has been approved by wesleywiser

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 9, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 9, 2022
…ice, r=wesleywiser

Better suggestions when user tries to collect into an unsized `[_]`

1. Extend the predicate on `rustc_on_unimplemented` to support substitutions like note, label, etc (i.e. treat it as a `OnUnimplementedFormatString`) so we can have slightly more general `rustc_on_unimplemented` special-cases.
2. Add a `rustc_on_unimplemented` if we fail on `FromIterator<A> for [A]` which happens when we don't explicitly collect into a `vec<A>`, but then pass the return from a `.collect` call into something that takes a slice.

Fixes rust-lang#91423
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 10, 2022
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#91443 (Better suggestions when user tries to collect into an unsized `[_]`)
 - rust-lang#91504 (`#[used(linker)]` attribute)
 - rust-lang#93503 (debuginfo: Fix DW_AT_containing_type vtable debuginfo regression)
 - rust-lang#93753 (Complete removal of #[main] attribute from compiler)
 - rust-lang#93799 (Fix typo in `std::fmt` docs)
 - rust-lang#93813 (Make a few cleanup MIR passes public)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9634559 into rust-lang:master Feb 10, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 10, 2022
@meithecatte
Copy link
Contributor

What would it take to add a structured suggestion to this diagnostic?

@compiler-errors
Copy link
Member Author

@NieDzejkob, what do you mean by this? I don't think the rustc_on_unimplemented attribute supports suggestions. You'd probably need to rip this PR out and replace it with a full-fledged diagnostic that is emitted from the compiler itself.

If you're interested in that route, you probably have a good bet putting some logic to detect this case in report_selection_error in rustc_trait_selection::traits::error_reporting.

@compiler-errors compiler-errors deleted the bad_collect_into_slice branch November 2, 2022 02:49
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type inference around Iterator::collect can result in confusing error messages
9 participants